<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="servlets.*"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script>
$("a.locals").click(function() {
		$("#mainPage_content").hide().fadeIn(1000).load("main/localProfile.jsp?local_id="+ $(this).attr('id'));
		return false;
	});
</script>

<div class="page-header">
	<h2 class="page-title">Nasze lokale</h2>
</div>
<div id="content">
<br />
<%
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
						LocalMethods lm = new LocalMethods();
							response.setContentType("text/html");
							List<Local> locals = lm.listAllLocals(sessionFactory, s); 
							FeedbackMethods fb = new FeedbackMethods();
					%> 
			<table>
<%
		if (locals.size() > 0) {
	for (Local l : locals) {
		int local_id = l.getLocal_id();
		String localName = l.getCity() + ", "+ l.getStreet()+ " "+l.getLocal_number();
		%>
<tr>
<td>
		<div class="col-md-4 col-sm-6" style="width: 666px;">
											<div class="team-member">
												 <div class="member-thumb">
												<!--	<img src="images/team3.jpg" alt=""> -->
												</div>
												<div class="member-infos">
													<h4 class="member-name">
													<%out.println("<a class=\"locals\" id=\""+ local_id + "\" href=\"#\">" + localName + "</a>"); %></h4>
													<span class="member-role">
													<%out.println("Ogólna ocena uzytkownikow:"+ "  "); %>
													<br />
													<%
													int commentsCount = fb.countFbByLocalId(sessionFactory, s, local_id);
													out.println("Komentarzy: "+ commentsCount); %>
													</span>
													
													<% String opis1 = null;
													if (l.getDescription()== null || l.getDescription().equals("0")) opis1 = "Brak";
													else opis1 = l.getDescription();%>
													<p class="member-desc"><%out.println("Opis lokalu: "+ opis1);%></p>
													<p class="comments"></p>
												</div>
											</div>
										</div>
										<!-- /.col-md-4 -->
									
									</td>
									</tr>
									<tr> <td><br /></td></tr>
								
		<%
		}
	%>
	
	</table>
	<%
		}
		s.getTransaction().commit();
		%>

</div>		
		